-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
41 lines (34 loc) · 997 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
int main() {
int i, N, quantia, somaC = 0, somaR = 0, somaS = 0, totalCobaia;
double porC, porR, porS;
char tipo;
scanf("%d", &N);
for(i = 0; i < N; i++){
do{
scanf("%d %c", &quantia, &tipo);
}while(tipo != 'C' && tipo != 'R' && tipo != 'S');
switch (tipo){
case 'C':
somaC += quantia;
break;
case 'R':
somaR += quantia;
break;
case 'S':
somaS += quantia;
}
}
totalCobaia = somaC + somaR + somaS;
porC = (double)(100 * somaC) / totalCobaia;
porR = (double)(100 * somaR) / totalCobaia;
porS = (double)(100 * somaS) / totalCobaia;
printf("Total: %d cobaias\n", totalCobaia);
printf("Total de coelhos: %d\n", somaC);
printf("Total de ratos: %d\n", somaR);
printf("Total de sapos: %d\n", somaS);
printf("Percentual de coelhos: %.2lf %%\n", porC);
printf("Percentual de ratos: %.2lf %%\n", porR);
printf("Percentual de sapos: %.2lf %%\n", porS);
return 0;
}